//
//  AppDelegate.m
//  guahao
//
//  Created by osx on 16/9/19.
//  Copyright © 2016年 osx. All rights reserved.
//

#import "AppDelegate.h"
#import "BaseNavigationController.h"
#import "DrawerViewController.h"
#import "LeftMenuTableViewController.h"
#import "HomeViewController.h"
#import "LeftMenuLogedInTableViewController.h"
#import "DefineTools.h"
//#import "CZLoopImagesController.h"
//#import "LoopImageViewController.h"
#import "JHLoginViewController.h"
#import "UserInfoModel.h"
#import "GHDocterController.h"
#import <RongIMLib/RongIMLib.h>

@interface AppDelegate ()

//@property (nonatomic, strong) UserInfoModel *userinfo;

@end

@implementation AppDelegate

//-(UserInfoModel *)userinfo{
//
//    if (!_userinfo) {
//        _userinfo = [[UserInfoModel alloc] init];
//    }
//    
//    return _userinfo;
//}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    [[RCIMClient sharedRCIMClient] initWithAppKey:@"bmdehs6pdbhws"];
    
    
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    
    [self setRootVC];
    [self resigNf];
    
    self.window.makeKeyAndVisible;
    
    
    [UserInfoModel shareUserInfoModel].isLogin = 0;
    return YES;
}

-(void)resigNf{
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setRootVC) name:@"setRootVC" object:nil];
}

-(void)setRootVC{
    
    
    if ([UserInfoModel shareUserInfoModel].roles == 1) {
        GHDocterController *doc = [[GHDocterController alloc] init];
        
        self.window.rootViewController = doc;
        
        return;
    }
    
    
    //创建首页
    HomeViewController * homeViewController = [[HomeViewController alloc]init];
    // LoopImageViewController* homeViewController = [[LoopImageViewController alloc] init];
    //JHLoginViewController * homeViewController = [[JHLoginViewController alloc] init];
    BaseNavigationController * naVC =[[BaseNavigationController alloc]initWithRootViewController:homeViewController ];
    //创建左侧菜单
    
    LeftMenuTableViewController * leftVC = [[LeftMenuTableViewController alloc]init];
    
    
    //如果登陆了跳转到登陆后的视图(继承自访客控制器,继承属性)
    if ([UserInfoModel shareUserInfoModel].isLogin) {
        leftVC = [[LeftMenuLogedInTableViewController alloc] init ];
    }
    else {
        leftVC = [[LeftMenuTableViewController alloc] init];
    }
    BaseNavigationController *baseVC = [[BaseNavigationController alloc] initWithRootViewController:leftVC];
    
    //实现抽屉效果
    self.drawerVC= [[DrawerViewController alloc] initWithCenterViewController:naVC leftDrawerViewController:baseVC];
    [self.drawerVC setShowsShadow:YES];
    // 右控制器的初始宽度
    [self.drawerVC setMaximumLeftDrawerWidth:KScreenWidth*0.75];
    // 打开手势操作区域
    [self.drawerVC setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
    // 关闭手势操作区域
    [self.drawerVC setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    //设置为主窗口的根控制器
    self.window.rootViewController = self.drawerVC;
    
}




























- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
